package com.cmc.cloud.cmclink.doc.controller.admin.special;

import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.convert.SpecialCargoOogConvert;
import com.cmc.cloud.cmclink.doc.entity.PortTerminalMaxArgDO;
import com.cmc.cloud.cmclink.doc.entity.SpecialCargoOogDO;
import com.cmc.cloud.cmclink.doc.service.SpecialCargoOogService;
import com.cmc.cloud.cmclink.doc.vo.specialcargooogvo.*;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import com.cmes.framework.operatelog.core.annotations.OperateLog;
import com.cmes.framework.operatelog.core.enums.OperateTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;


/**
 * 特种货审批oog前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 特种货审批oog")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/specialCargoOog")
public class SpecialCargoOogController {

    @Resource
    private SpecialCargoOogService specialCargoOogService;

    @Operation(summary = "创建特种货审批oog")
    @PostMapping("/create")
    public CommonResult<Void> createSpecialCargoOog(@Valid @RequestBody SpecialCargoOogCreateReqVO createReqVO) {
        specialCargoOogService.createSpecialCargoOog(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新特种货审批oog")
    @PostMapping("/update")
    public CommonResult<Void> updateSpecialCargoOog(@Valid @RequestBody SpecialCargoOogUpdateReqVO updateReqVO) {
        specialCargoOogService.updateSpecialCargoOog(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除特种货审批oog")
    @PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Void> deleteSpecialCargoOog(@PathVariable("id") Long id) {
        specialCargoOogService.deleteSpecialCargoOog(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得特种货审批oog")
    @GetMapping("/get/{cntrId}")
    @Parameter(name = "cntrId", description = "箱型ID", required = true, example = "1024")
    public CommonResult<SpecialCargoOogRespVO> getSpecialCargoOog(@PathVariable("cntrId") Long cntrId) {
        SpecialCargoOogDO specialCargoOog = specialCargoOogService.getSpecialCargoOog(cntrId);
        return CommonResult.success(SpecialCargoOogConvert.INSTANCE.convert(specialCargoOog));
    }

    @Operation(summary = "获得特种货审批oog列表")
    @GetMapping("/list")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<SpecialCargoOogRespVO>> getSpecialCargoOogList(@RequestParam("ids") Collection<Long> ids) {
        List<SpecialCargoOogDO> list = specialCargoOogService.getSpecialCargoOogList(ids);
        return CommonResult.success(SpecialCargoOogConvert.INSTANCE.convertList(list));
    }

    @Operation(summary = "获得特种货审批oog分页")
    @PostMapping("/page")
    public CommonResult<PageResult<SpecialCargoOogRespVO>> getSpecialCargoOogPage(@RequestBody @Valid SpecialCargoOogPageReqVO pageVO) {
        PageResult<SpecialCargoOogDO> pageResult = specialCargoOogService.getSpecialCargoOogPage(pageVO);
        List<SpecialCargoOogRespVO> results = SpecialCargoOogConvert.INSTANCE.convertList(pageResult.getList());
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }

    @Operation(summary = "创建-框架箱参数维护")
    @PostMapping("/createMaxArg")
    @OperateLog(name = "创建-框架箱参数维护", type = OperateTypeEnum.CREATE)
    public CommonResult<Void> createMaxArg(@Valid @RequestBody PortTerminalMaxArgBaseVO createReqVO) {
        specialCargoOogService.createPortTerminalMaxArg(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新-框架箱参数维护")
    @PostMapping("/updateMaxArg")
    @OperateLog(name = "更新-框架箱参数维护", type = OperateTypeEnum.UPDATE)
    public CommonResult<Void> updateMaxArg(@Valid @RequestBody PortTerminalMaxArgBaseVO updateReqVO) {
        specialCargoOogService.updatePortTerminalMaxArg(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除-框架箱参数维护")
    @PostMapping("/deleteMaxArg/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    @OperateLog(name = "删除-框架箱参数维护", type = OperateTypeEnum.DELETE)
    public CommonResult<Void> deleteMaxArg(@PathVariable("id") Long id) {
        specialCargoOogService.deletePortTerminalMaxArg(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得-框架箱参数维护")
    @GetMapping("/getMaxArg/{id}")
    @UseResponsePropertyAdvice
    @Parameter(name = "id", required = true, example = "1024")
    @OperateLog(name = "获得-框架箱参数维护", type = OperateTypeEnum.GET)
    public CommonResult<PortTerminalMaxArgBaseVO> getPortTerminalMaxArg(@PathVariable("id") Long id) {
        PortTerminalMaxArgDO specialCargoOog = specialCargoOogService.getPortTerminalMaxArg(id);
        return CommonResult.success(SpecialCargoOogConvert.INSTANCE.convert(specialCargoOog));
    }


    @Operation(summary = "分页-框架箱参数维护")
    @PostMapping("/pageMaxArg")
    @OperateLog(name = "分页-框架箱参数维护", type = OperateTypeEnum.GET)
    @UseResponsePropertyAdvice
    public CommonResult<PageResult<PortTerminalMaxArgBaseVO>> pageMaxArg(@RequestBody @Valid PortTerminalMaxArgPageReqVO pageVO) {
        PageResult<PortTerminalMaxArgBaseVO> pageResult = specialCargoOogService.getPortTerminalMaxArgPage(pageVO);
        return CommonResult.success(pageResult);
    }

    @Operation(summary = "审批同意检查AK,FLEXI箱体信息")
    @PostMapping("/checkMaxArg")
    @Parameter(name = "applyId", description = "主信息id", required = true)
    @Parameter(name = "voyageId", description = "审批航线信息id", required = true)
    @OperateLog(name = "审批同意检查AK,FLEXI箱体信息", type = OperateTypeEnum.GET)
    public CommonResult<String> checkMaxArg(@RequestParam("applyId") Long applyId, @RequestParam(value = "voyageId") Long voyageId) {
        String results = specialCargoOogService.checkMaxArg(applyId, voyageId);
        return CommonResult.success(results);
    }
}
